import 'package:flutter/material.dart';
import 'package:speed_random/common/common_fuc.dart';
import 'package:speed_random/core/config/app_config.dart';
import 'package:speed_random/core/services/ad_service.dart';
// 封装的新组件
class itemHomeList extends StatelessWidget {
  final String text;
  final String imagePath;
  final Color backgroundColor;
  // 新增点击回调函数
  final VoidCallback? onTap;

  const itemHomeList({
    Key? key,
    required this.text,
    this.imagePath = 'images/123.png', // 设置默认图片路径
    this.backgroundColor = Colors.grey, // 设置默认背景颜色
    this.onTap, // 添加可选参数
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      // 绑定点击事件
      onTap: ()async{


        AppConfig.current.adService.showAd(adType: AdType.interstitial);


        onTap?.call(); // 调用回调函数
      },
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 5),
        height: 100,
      // ... existing code ...
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16),
          gradient: LinearGradient(
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
            colors: [
              commonFuc.hexToColor("#ff8177"),

              //commonFuc.hexToColor("#000000"),
              commonFuc.hexToColor("#b12a5b"),
              /*backgroundColor,
              backgroundColor.withOpacity(0.8),
              backgroundColor.withOpacity(0.5),*/
            ],
          ),
        ),
// ... existing code ...

        padding: EdgeInsets.all(16),
        child: Row(
          children: [
            // 左边文字部分
            Expanded(
              child: Text(
                text,
                style: TextStyle(fontSize: 26, color: Colors.white,fontWeight: FontWeight.bold),
              ),
            ),
            // 右边图片部分
            Image.asset(
              imagePath,
              fit: BoxFit.cover,
              width: 70,
            ),
          ],
        ),
      ),
    );
  }
}